package com.ruoyi.web.controller.teacher;

import java.util.List;
import java.util.Map;
import java.util.UUID;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.dto.BasisLoadingUavCamp;
import com.ruoyi.service.IBasisUavTableService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.domain.BasisUav;
import com.ruoyi.service.IBasisUavService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 无人机Controller
 * 
 * @author wangzebing
 * @date 2025-05-24
 */
@RestController
@RequestMapping("/system/uav")
public class BasisUavController extends BaseController
{
    @Autowired
    private IBasisUavService basisUavService;

    @Autowired
    private IBasisUavTableService basisUavTableService;

    /**
     * 查询无人机列表
     */
    @GetMapping("/list")
    public TableDataInfo list(BasisUav basisUav)
    {
        startPage();
        List<BasisUav> list = basisUavService.selectBasisUavList(basisUav);
        return getDataTable(list);
    }



    @GetMapping("/findAllBasisUav")
    public AjaxResult findAllBasisUav()
    {
        List<BasisUav> list = basisUavService.selectBasisUavList(new BasisUav());
        return success(list);
    }

    /**
     * 导出无人机列表
     */
    @Log(title = "无人机", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BasisUav basisUav)
    {
        List<BasisUav> list = basisUavService.selectBasisUavList(basisUav);
        ExcelUtil<BasisUav> util = new ExcelUtil<BasisUav>(BasisUav.class);
        util.exportExcel(response, list, "无人机数据");
    }

    /**
     * 获取无人机详细信息
     */
    @GetMapping(value = "/{uavId}")
    public AjaxResult getInfo(@PathVariable("uavId") Long uavId)
    {
        return success(basisUavService.selectBasisUavByUavId(uavId));
    }

    /**
     * 新增无人机
     */
    @Log(title = "无人机", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BasisUav basisUav)
    {
        basisUav.setType("无人机");
        UUID uuid = UUID.randomUUID();
        basisUav.setUuid(uuid.toString());
        return toAjax(basisUavService.insertBasisUav(basisUav));
    }

    /**
     * 修改无人机
     */
    @Log(title = "无人机", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BasisUav basisUav)
    {
        return toAjax(basisUavService.updateBasisUav(basisUav));
    }

    /**
     * 删除无人机
     */
    @Log(title = "无人机", businessType = BusinessType.DELETE)
	@DeleteMapping("/{uavIds}")
    public AjaxResult remove(@PathVariable Long[] uavIds)
    {
        return toAjax(basisUavService.deleteBasisUavByUavIds(uavIds));
    }


    @Log(title = "无人机", businessType = BusinessType.INSERT)
    @PostMapping("/addBasisLoadingUavCamp")
    public AjaxResult addBasisLoadingUavCamp(@RequestBody BasisLoadingUavCamp basisLoadingUavCamp)
    {
        return success(basisUavService.addBasisLoadingUavCamp(basisLoadingUavCamp));
    }


    @Log(title = "无人机", businessType = BusinessType.UPDATE)
    @PostMapping("/updateBasisLoadingUavCamp")
    public AjaxResult updateBasisLoadingUavCamp(@RequestBody BasisLoadingUavCamp basisLoadingUavCamp)
    {
        return success(basisUavService.updateBasisLoadingUavCamp(basisLoadingUavCamp));
    }

    //导调角色修改目标
    @PostMapping("/updateBasisLoadingUavCampDt")
    public AjaxResult updateBasisLoadingUavCampDt(@RequestBody BasisLoadingUavCamp basisLoadingUavCamp)
    {
        return success(basisUavService.updateBasisLoadingUavCampDt(basisLoadingUavCamp));
    }


    @GetMapping(value = "/delBasisLoadingUavCamp")
    public AjaxResult delBasisLoadingUavCamp(String loadingId, Integer uavId)
    {
        boolean b = basisUavService.delBasisLoadingUavCamp(loadingId, uavId);
        if (b){
            boolean b1 = basisUavTableService.delByLoadingIdAndUavIdfFormUavTable(loadingId, uavId);
            if (!b1) return success(false);
        }
        return success(b);
    }


    @GetMapping(value = "/fidnByBasisLoadingUavCamp")
    public AjaxResult fidnByBasisLoadingUavCamp(String loadingId, Integer uavId)
    {
        return success(basisUavService.fidnByBasisLoadingUavCamp(loadingId, uavId));
    }


    @GetMapping(value = "/fidnByBasisLoadingUavCampDT")
    public AjaxResult fidnByBasisLoadingUavCampDT(String loadingId, Integer uavId)
    {
        return success(basisUavService.fidnByBasisLoadingUavCampDT(loadingId, uavId));
    }

    //根据案例和阵营查询无人机
    @GetMapping(value = "/findByLoadingIdAndCampIdFormUav")
    public AjaxResult findByLoadingIdAndCampIdFormUav(String loadingId, Integer campId)
    {
        return success(basisUavService.findByLoadingIdAndCampId2(loadingId, campId));
    }

    //根据案例id查询 没有跟当前案例相关联的目标
    @GetMapping(value = "/selectBasisUavLoadingId")
    public AjaxResult selectBasisUavLoading(String loadingId)
    {
        return success(basisUavService.selectBasisUavLoading(loadingId));
    }

    @GetMapping(value = "/selectBasisUavLoadingIdDT")
    public AjaxResult selectBasisUavLoadingIdDT(String loadingId)
    {
        return success(basisUavService.selectBasisUavLoadingDT(loadingId));
    }



}
